
import 'package:flutter/material.dart';
import 'package:xsdk_flutter/xsdk/framework/base/xsdk_function.dart';
import 'package:xsdk_flutter/xsdk/framework/component/select_address/bean/x_address_json.dart';
import 'package:xsdk_flutter/xsdk/framework/component/select_address/bean/x_bean_address.dart';
import 'package:xsdk_flutter/xsdk/framework/component/select_address/widget/x_state_widget_select_address.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_flutter.dart';
import 'package:xsdk_flutter/xsdk/utils/json/x_utils_json.dart';

/*
自定义选择地址控件
 */
abstract class XSelectAddressUtils{

  //弹出选择地址控件(底部弹框)
  static void showSelectAddressWidgetByBottomSheet(
      BuildContext contextOfScaffold,
      {
        required XFunctionResultCallback<dynamic> resultCallback, //返回的是Map<String,dynamic>
        List<XBeanAddressInfoData>? addressInfoDataList,
        XBeanSelectAddress? selectAddressResult,
      }
      ){


    if(addressInfoDataList==null){
      addressInfoDataList=[];
      Map<String,dynamic> map=XJsonUtils.json2Map(XAddressData.json_address);
      List<dynamic> addressList=map['data'];
      for(dynamic iitem in addressList){
        addressInfoDataList.add(XBeanAddressInfoData.fromJson(iitem));
      }
    }


    XFlutterUtils.openBottomSheet(
      context: contextOfScaffold,
      backgroundColor: Colors.white,
      shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(15),
            topRight: Radius.circular(15),
          )
      ),
      onCallbackResult: resultCallback,
      enableDrag: false,
      widgetState: XSelectAddressState(
          addressInfoDataList: addressInfoDataList,
          selectAddressResultMap:selectAddressResult?.toJson(),
      ),
    );
  }


}
